<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>注册PL博客账号</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/assets/css/beyond.min.css">
<script type="text/javascript" src="js/jquery.min.js"></script>
</head>
<body>
<form method="post">
<div style="position: absolute;top: 50%;left: 50%;-webkit-transform:translate(-50%,-50%);" class="col-lg-6 col-sm-6 col-xs-12" >
       <div class="widget flat radius-bordered">
           <div class="widget-header bg-blue">
               <span class="widget-caption">注册PL博客账号</span>
           </div>
           <div class="widget-body">
               <div id="registration-form">
                   <form role="form">
                       <div class="form-title">
                           	填写用户信息
                       </div>
                       <div class="form-group">
                           <span class="input-icon icon-right">
                               <input name="username" required type="text" class="form-control" id="userameInput" placeholder="用户名">
                               <i class="glyphicon glyphicon-user circular"></i>
                           </span>
                       </div>
                       <div class="form-group">
                           <span class="input-icon icon-right">
                               <input name="email" type="email" required class="form-control" id="emailInput" placeholder="邮箱">
                               <i class="fa fa-envelope-o circular"></i>
                           </span>
                       </div>
                       <div class="form-group">
                           <span class="input-icon icon-right">
                               <input name="pwd" type="password" required class="form-control" id="passwordInput" placeholder="密码">
                               <i class="fa fa-lock circular"></i>
                           </span>
                       </div>
                       <div class="form-group">
                           <span class="input-icon icon-right">
                               <input name="pwd2" type="password" required class="form-control" id="confirmPasswordInput" placeholder="确认密码">
                               <i class="fa fa-lock circular"></i>
                           </span>
                       </div>
                       <div class="form-group">
                           <div class="checkbox">
                               <label>
                               	   <input type="checkbox" id="link" class="colored-blue" value="true">
                                 
                                   <span class="text">注册成功后自动登录</span>
                               </label>
                           </div>
                       </div>
                       <div style="height:50px;line-height:50px;">
			          	<a href="login.jsp">《已有账号？前去登录</a>
			          	<button style="float:right;width:120px;letter-spacing:2px;border-radius:2px;" id="regBtn" type="submit" class="btn btn-blue">创建账户</button>
			          </div>
                       
                   </form>
               </div>
           </div>
       </div>
   </div>
</form>
</body>
<script>
$("form").submit(function(){
    //这里是要执行的代码
    event.preventDefault();
});
  function checkpwd(num1,num2){
    if (num1===num2) {
      return true;
    }
    return false;
  }
  $("#regBtn").click(function(event){
    var username = $("#userameInput").val().trim();
    var email = $("#emailInput").val().trim();
    var pwd = $("#passwordInput").val().trim();
    var pwd2 = $("#confirmPasswordInput").val().trim();
    var link = $("#link").is(':checked');
    if (checkpwd(pwd,pwd2) && username!="" && email!="" && pwd!="") {
      $.post("register_action.jsp",{
    	username:username,
        email:email,
        pwd:pwd,
        pwd2:pwd2
      },function(res){
        if(res=="false"){alert("注册失败！");}
        else if (res=="true") {
          alert("注册成功！");
          if (link==true) {
            location.href="index.jsp?username="+username;
          }
        }else{
        	alert(res);
        }
      });
    }else if(!checkpwd(pwd,pwd2)){
      alert("两次输入的密码不一致！");
    }
  });
</script>
</html>
